//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;
using System.Windows.Media;

namespace OpenLS.Spreadsheet.UI
{
    [ContentProperty("Colors")]
    public class IndexedColorsConverter: IValueConverter
    {
        private List<Color> colors = new List<Color>();

        public List<Color> Colors
        {
            get { return colors; }
            set { colors = value; }
        }


        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int i = (int)value;
            i = i % Colors.Count;
            return Colors[i];
        }
        public Brush IndexToBrush(int i)
        {
            i = i % Colors.Count;
            return new SolidColorBrush(Colors[i]);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}
